package cn.itcast.order.service;

import cn.itcast.feign.clients.UserClients;
import cn.itcast.feign.pojo.Order;
import cn.itcast.feign.pojo.User;
import cn.itcast.order.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class OrderService {


//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private UserClients userClient;

    @Autowired
    private OrderMapper orderMapper;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
//
//        String url="http://userservice/user/"+ order.getUserId();
//        cn.itcast.order.pojo.User forObject = restTemplate.getForObject(url, User.class);


        User forObject = userClient.findById(order.getUserId());
        order.setUser(forObject);
        // 4.返回
        return order;
    }





}
